//! Common GL function loading for Linux (X11 and Wayland).

use std::{
    ffi::{c_void, CString},
    rc::Rc,
};

use gl_context_loader::GenericGlContext;

use super::super::x11::dlopen::{Egl, Library};
use crate::desktop::shell2::common::dlopen::DynamicLibrary;

/// Wrapper to get access to the GL function pointers
pub struct GlFunctions {
    _opengl_lib_handle: Option<Library>,
    pub functions: Rc<GenericGlContext>,
}

impl std::fmt::Debug for GlFunctions {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "GlFunctions {{ ... }}")
    }
}

impl GlFunctions {
    /// Allocates and loads the OpenGL function pointers via eglGetProcAddress.
    pub fn initialize(egl: &Rc<Egl>) -> Result<Self, String> {
        let opengl_lib = Library::load("libGL.so.1").ok();

        fn get_func(egl: &Egl, s: &str, lib: &Option<Library>) -> *mut gl_context_loader::c_void {
            let symbol_name = CString::new(s).unwrap();
            let addr = unsafe { (egl.eglGetProcAddress)(symbol_name.as_ptr()) };
            if !addr.is_null() {
                return addr as *mut gl_context_loader::c_void;
            }
            if let Some(lib) = lib {
                if let Ok(addr) = unsafe { lib.get_symbol::<*mut c_void>(s) } {
                    return addr as *mut gl_context_loader::c_void;
                }
            }
            std::ptr::null_mut()
        }

        let context = GenericGlContext {
            glAccum: get_func(egl, "glAccum", &opengl_lib),
            glActiveTexture: get_func(egl, "glActiveTexture", &opengl_lib),
            glAlphaFunc: get_func(egl, "glAlphaFunc", &opengl_lib),
            glAreTexturesResident: get_func(egl, "glAreTexturesResident", &opengl_lib),
            glArrayElement: get_func(egl, "glArrayElement", &opengl_lib),
            glAttachShader: get_func(egl, "glAttachShader", &opengl_lib),
            glBegin: get_func(egl, "glBegin", &opengl_lib),
            glBeginConditionalRender: get_func(egl, "glBeginConditionalRender", &opengl_lib),
            glBeginQuery: get_func(egl, "glBeginQuery", &opengl_lib),
            glBeginTransformFeedback: get_func(egl, "glBeginTransformFeedback", &opengl_lib),
            glBindAttribLocation: get_func(egl, "glBindAttribLocation", &opengl_lib),
            glBindBuffer: get_func(egl, "glBindBuffer", &opengl_lib),
            glBindBufferBase: get_func(egl, "glBindBufferBase", &opengl_lib),
            glBindBufferRange: get_func(egl, "glBindBufferRange", &opengl_lib),
            glBindFragDataLocation: get_func(egl, "glBindFragDataLocation", &opengl_lib),
            glBindFragDataLocationIndexed: get_func(
                egl,
                "glBindFragDataLocationIndexed",
                &opengl_lib,
            ),
            glBindFramebuffer: get_func(egl, "glBindFramebuffer", &opengl_lib),
            glBindRenderbuffer: get_func(egl, "glBindRenderbuffer", &opengl_lib),
            glBindSampler: get_func(egl, "glBindSampler", &opengl_lib),
            glBindTexture: get_func(egl, "glBindTexture", &opengl_lib),
            glBindVertexArray: get_func(egl, "glBindVertexArray", &opengl_lib),
            glBindVertexArrayAPPLE: get_func(egl, "glBindVertexArrayAPPLE", &opengl_lib),
            glBitmap: get_func(egl, "glBitmap", &opengl_lib),
            glBlendBarrierKHR: get_func(egl, "glBlendBarrierKHR", &opengl_lib),
            glBlendColor: get_func(egl, "glBlendColor", &opengl_lib),
            glBlendEquation: get_func(egl, "glBlendEquation", &opengl_lib),
            glBlendEquationSeparate: get_func(egl, "glBlendEquationSeparate", &opengl_lib),
            glBlendFunc: get_func(egl, "glBlendFunc", &opengl_lib),
            glBlendFuncSeparate: get_func(egl, "glBlendFuncSeparate", &opengl_lib),
            glBlitFramebuffer: get_func(egl, "glBlitFramebuffer", &opengl_lib),
            glBufferData: get_func(egl, "glBufferData", &opengl_lib),
            glBufferStorage: get_func(egl, "glBufferStorage", &opengl_lib),
            glBufferSubData: get_func(egl, "glBufferSubData", &opengl_lib),
            glCallList: get_func(egl, "glCallList", &opengl_lib),
            glCallLists: get_func(egl, "glCallLists", &opengl_lib),
            glCheckFramebufferStatus: get_func(egl, "glCheckFramebufferStatus", &opengl_lib),
            glClampColor: get_func(egl, "glClampColor", &opengl_lib),
            glClear: get_func(egl, "glClear", &opengl_lib),
            glClearAccum: get_func(egl, "glClearAccum", &opengl_lib),
            glClearBufferfi: get_func(egl, "glClearBufferfi", &opengl_lib),
            glClearBufferfv: get_func(egl, "glClearBufferfv", &opengl_lib),
            glClearBufferiv: get_func(egl, "glClearBufferiv", &opengl_lib),
            glClearBufferuiv: get_func(egl, "glClearBufferuiv", &opengl_lib),
            glClearColor: get_func(egl, "glClearColor", &opengl_lib),
            glClearDepth: get_func(egl, "glClearDepth", &opengl_lib),
            glClearIndex: get_func(egl, "glClearIndex", &opengl_lib),
            glClearStencil: get_func(egl, "glClearStencil", &opengl_lib),
            glClientActiveTexture: get_func(egl, "glClientActiveTexture", &opengl_lib),
            glClientWaitSync: get_func(egl, "glClientWaitSync", &opengl_lib),
            glClipPlane: get_func(egl, "glClipPlane", &opengl_lib),
            glColor3b: get_func(egl, "glColor3b", &opengl_lib),
            glColor3bv: get_func(egl, "glColor3bv", &opengl_lib),
            glColor3d: get_func(egl, "glColor3d", &opengl_lib),
            glColor3dv: get_func(egl, "glColor3dv", &opengl_lib),
            glColor3f: get_func(egl, "glColor3f", &opengl_lib),
            glColor3fv: get_func(egl, "glColor3fv", &opengl_lib),
            glColor3i: get_func(egl, "glColor3i", &opengl_lib),
            glColor3iv: get_func(egl, "glColor3iv", &opengl_lib),
            glColor3s: get_func(egl, "glColor3s", &opengl_lib),
            glColor3sv: get_func(egl, "glColor3sv", &opengl_lib),
            glColor3ub: get_func(egl, "glColor3ub", &opengl_lib),
            glColor3ubv: get_func(egl, "glColor3ubv", &opengl_lib),
            glColor3ui: get_func(egl, "glColor3ui", &opengl_lib),
            glColor3uiv: get_func(egl, "glColor3uiv", &opengl_lib),
            glColor3us: get_func(egl, "glColor3us", &opengl_lib),
            glColor3usv: get_func(egl, "glColor3usv", &opengl_lib),
            glColor4b: get_func(egl, "glColor4b", &opengl_lib),
            glColor4bv: get_func(egl, "glColor4bv", &opengl_lib),
            glColor4d: get_func(egl, "glColor4d", &opengl_lib),
            glColor4dv: get_func(egl, "glColor4dv", &opengl_lib),
            glColor4f: get_func(egl, "glColor4f", &opengl_lib),
            glColor4fv: get_func(egl, "glColor4fv", &opengl_lib),
            glColor4i: get_func(egl, "glColor4i", &opengl_lib),
            glColor4iv: get_func(egl, "glColor4iv", &opengl_lib),
            glColor4s: get_func(egl, "glColor4s", &opengl_lib),
            glColor4sv: get_func(egl, "glColor4sv", &opengl_lib),
            glColor4ub: get_func(egl, "glColor4ub", &opengl_lib),
            glColor4ubv: get_func(egl, "glColor4ubv", &opengl_lib),
            glColor4ui: get_func(egl, "glColor4ui", &opengl_lib),
            glColor4uiv: get_func(egl, "glColor4uiv", &opengl_lib),
            glColor4us: get_func(egl, "glColor4us", &opengl_lib),
            glColor4usv: get_func(egl, "glColor4usv", &opengl_lib),
            glColorMask: get_func(egl, "glColorMask", &opengl_lib),
            glColorMaski: get_func(egl, "glColorMaski", &opengl_lib),
            glColorMaterial: get_func(egl, "glColorMaterial", &opengl_lib),
            glColorP3ui: get_func(egl, "glColorP3ui", &opengl_lib),
            glColorP3uiv: get_func(egl, "glColorP3uiv", &opengl_lib),
            glColorP4ui: get_func(egl, "glColorP4ui", &opengl_lib),
            glColorP4uiv: get_func(egl, "glColorP4uiv", &opengl_lib),
            glColorPointer: get_func(egl, "glColorPointer", &opengl_lib),
            glCompileShader: get_func(egl, "glCompileShader", &opengl_lib),
            glCompressedTexImage1D: get_func(egl, "glCompressedTexImage1D", &opengl_lib),
            glCompressedTexImage2D: get_func(egl, "glCompressedTexImage2D", &opengl_lib),
            glCompressedTexImage3D: get_func(egl, "glCompressedTexImage3D", &opengl_lib),
            glCompressedTexSubImage1D: get_func(egl, "glCompressedTexSubImage1D", &opengl_lib),
            glCompressedTexSubImage2D: get_func(egl, "glCompressedTexSubImage2D", &opengl_lib),
            glCompressedTexSubImage3D: get_func(egl, "glCompressedTexSubImage3D", &opengl_lib),
            glCopyBufferSubData: get_func(egl, "glCopyBufferSubData", &opengl_lib),
            glCopyImageSubData: get_func(egl, "glCopyImageSubData", &opengl_lib),
            glCopyPixels: get_func(egl, "glCopyPixels", &opengl_lib),
            glCopyTexImage1D: get_func(egl, "glCopyTexImage1D", &opengl_lib),
            glCopyTexImage2D: get_func(egl, "glCopyTexImage2D", &opengl_lib),
            glCopyTexSubImage1D: get_func(egl, "glCopyTexSubImage1D", &opengl_lib),
            glCopyTexSubImage2D: get_func(egl, "glCopyTexSubImage2D", &opengl_lib),
            glCopyTexSubImage3D: get_func(egl, "glCopyTexSubImage3D", &opengl_lib),
            glCreateProgram: get_func(egl, "glCreateProgram", &opengl_lib),
            glCreateShader: get_func(egl, "glCreateShader", &opengl_lib),
            glCullFace: get_func(egl, "glCullFace", &opengl_lib),
            glDebugMessageCallback: get_func(egl, "glDebugMessageCallback", &opengl_lib),
            glDebugMessageCallbackKHR: get_func(egl, "glDebugMessageCallbackKHR", &opengl_lib),
            glDebugMessageControl: get_func(egl, "glDebugMessageControl", &opengl_lib),
            glDebugMessageControlKHR: get_func(egl, "glDebugMessageControlKHR", &opengl_lib),
            glDebugMessageInsert: get_func(egl, "glDebugMessageInsert", &opengl_lib),
            glDebugMessageInsertKHR: get_func(egl, "glDebugMessageInsertKHR", &opengl_lib),
            glDeleteBuffers: get_func(egl, "glDeleteBuffers", &opengl_lib),
            glDeleteFencesAPPLE: get_func(egl, "glDeleteFencesAPPLE", &opengl_lib),
            glDeleteFramebuffers: get_func(egl, "glDeleteFramebuffers", &opengl_lib),
            glDeleteLists: get_func(egl, "glDeleteLists", &opengl_lib),
            glDeleteProgram: get_func(egl, "glDeleteProgram", &opengl_lib),
            glDeleteQueries: get_func(egl, "glDeleteQueries", &opengl_lib),
            glDeleteRenderbuffers: get_func(egl, "glDeleteRenderbuffers", &opengl_lib),
            glDeleteSamplers: get_func(egl, "glDeleteSamplers", &opengl_lib),
            glDeleteShader: get_func(egl, "glDeleteShader", &opengl_lib),
            glDeleteSync: get_func(egl, "glDeleteSync", &opengl_lib),
            glDeleteTextures: get_func(egl, "glDeleteTextures", &opengl_lib),
            glDeleteVertexArrays: get_func(egl, "glDeleteVertexArrays", &opengl_lib),
            glDeleteVertexArraysAPPLE: get_func(egl, "glDeleteVertexArraysAPPLE", &opengl_lib),
            glDepthFunc: get_func(egl, "glDepthFunc", &opengl_lib),
            glDepthMask: get_func(egl, "glDepthMask", &opengl_lib),
            glDepthRange: get_func(egl, "glDepthRange", &opengl_lib),
            glDetachShader: get_func(egl, "glDetachShader", &opengl_lib),
            glDisable: get_func(egl, "glDisable", &opengl_lib),
            glDisableClientState: get_func(egl, "glDisableClientState", &opengl_lib),
            glDisableVertexAttribArray: get_func(egl, "glDisableVertexAttribArray", &opengl_lib),
            glDisablei: get_func(egl, "glDisablei", &opengl_lib),
            glDrawArrays: get_func(egl, "glDrawArrays", &opengl_lib),
            glDrawArraysInstanced: get_func(egl, "glDrawArraysInstanced", &opengl_lib),
            glDrawBuffer: get_func(egl, "glDrawBuffer", &opengl_lib),
            glDrawBuffers: get_func(egl, "glDrawBuffers", &opengl_lib),
            glDrawElements: get_func(egl, "glDrawElements", &opengl_lib),
            glDrawElementsBaseVertex: get_func(egl, "glDrawElementsBaseVertex", &opengl_lib),
            glDrawElementsInstanced: get_func(egl, "glDrawElementsInstanced", &opengl_lib),
            glDrawElementsInstancedBaseVertex: get_func(
                egl,
                "glDrawElementsInstancedBaseVertex",
                &opengl_lib,
            ),
            glDrawPixels: get_func(egl, "glDrawPixels", &opengl_lib),
            glDrawRangeElements: get_func(egl, "glDrawRangeElements", &opengl_lib),
            glDrawRangeElementsBaseVertex: get_func(
                egl,
                "glDrawRangeElementsBaseVertex",
                &opengl_lib,
            ),
            glEdgeFlag: get_func(egl, "glEdgeFlag", &opengl_lib),
            glEdgeFlagPointer: get_func(egl, "glEdgeFlagPointer", &opengl_lib),
            glEdgeFlagv: get_func(egl, "glEdgeFlagv", &opengl_lib),
            glEnable: get_func(egl, "glEnable", &opengl_lib),
            glEnableClientState: get_func(egl, "glEnableClientState", &opengl_lib),
            glEnableVertexAttribArray: get_func(egl, "glEnableVertexAttribArray", &opengl_lib),
            glEnablei: get_func(egl, "glEnablei", &opengl_lib),
            glEnd: get_func(egl, "glEnd", &opengl_lib),
            glEndConditionalRender: get_func(egl, "glEndConditionalRender", &opengl_lib),
            glEndList: get_func(egl, "glEndList", &opengl_lib),
            glEndQuery: get_func(egl, "glEndQuery", &opengl_lib),
            glEndTransformFeedback: get_func(egl, "glEndTransformFeedback", &opengl_lib),
            glEvalCoord1d: get_func(egl, "glEvalCoord1d", &opengl_lib),
            glEvalCoord1dv: get_func(egl, "glEvalCoord1dv", &opengl_lib),
            glEvalCoord1f: get_func(egl, "glEvalCoord1f", &opengl_lib),
            glEvalCoord1fv: get_func(egl, "glEvalCoord1fv", &opengl_lib),
            glEvalCoord2d: get_func(egl, "glEvalCoord2d", &opengl_lib),
            glEvalCoord2dv: get_func(egl, "glEvalCoord2dv", &opengl_lib),
            glEvalCoord2f: get_func(egl, "glEvalCoord2f", &opengl_lib),
            glEvalCoord2fv: get_func(egl, "glEvalCoord2fv", &opengl_lib),
            glEvalMesh1: get_func(egl, "glEvalMesh1", &opengl_lib),
            glEvalMesh2: get_func(egl, "glEvalMesh2", &opengl_lib),
            glEvalPoint1: get_func(egl, "glEvalPoint1", &opengl_lib),
            glEvalPoint2: get_func(egl, "glEvalPoint2", &opengl_lib),
            glFeedbackBuffer: get_func(egl, "glFeedbackBuffer", &opengl_lib),
            glFenceSync: get_func(egl, "glFenceSync", &opengl_lib),
            glFinish: get_func(egl, "glFinish", &opengl_lib),
            glFinishFenceAPPLE: get_func(egl, "glFinishFenceAPPLE", &opengl_lib),
            glFinishObjectAPPLE: get_func(egl, "glFinishObjectAPPLE", &opengl_lib),
            glFlush: get_func(egl, "glFlush", &opengl_lib),
            glFlushMappedBufferRange: get_func(egl, "glFlushMappedBufferRange", &opengl_lib),
            glFogCoordPointer: get_func(egl, "glFogCoordPointer", &opengl_lib),
            glFogCoordd: get_func(egl, "glFogCoordd", &opengl_lib),
            glFogCoorddv: get_func(egl, "glFogCoorddv", &opengl_lib),
            glFogCoordf: get_func(egl, "glFogCoordf", &opengl_lib),
            glFogCoordfv: get_func(egl, "glFogCoordfv", &opengl_lib),
            glFogf: get_func(egl, "glFogf", &opengl_lib),
            glFogfv: get_func(egl, "glFogfv", &opengl_lib),
            glFogi: get_func(egl, "glFogi", &opengl_lib),
            glFogiv: get_func(egl, "glFogiv", &opengl_lib),
            glFramebufferRenderbuffer: get_func(egl, "glFramebufferRenderbuffer", &opengl_lib),
            glFramebufferTexture: get_func(egl, "glFramebufferTexture", &opengl_lib),
            glFramebufferTexture1D: get_func(egl, "glFramebufferTexture1D", &opengl_lib),
            glFramebufferTexture2D: get_func(egl, "glFramebufferTexture2D", &opengl_lib),
            glFramebufferTexture3D: get_func(egl, "glFramebufferTexture3D", &opengl_lib),
            glFramebufferTextureLayer: get_func(egl, "glFramebufferTextureLayer", &opengl_lib),
            glFrontFace: get_func(egl, "glFrontFace", &opengl_lib),
            glFrustum: get_func(egl, "glFrustum", &opengl_lib),
            glGenBuffers: get_func(egl, "glGenBuffers", &opengl_lib),
            glGenFencesAPPLE: get_func(egl, "glGenFencesAPPLE", &opengl_lib),
            glGenFramebuffers: get_func(egl, "glGenFramebuffers", &opengl_lib),
            glGenLists: get_func(egl, "glGenLists", &opengl_lib),
            glGenQueries: get_func(egl, "glGenQueries", &opengl_lib),
            glGenRenderbuffers: get_func(egl, "glGenRenderbuffers", &opengl_lib),
            glGenSamplers: get_func(egl, "glGenSamplers", &opengl_lib),
            glGenTextures: get_func(egl, "glGenTextures", &opengl_lib),
            glGenVertexArrays: get_func(egl, "glGenVertexArrays", &opengl_lib),
            glGenVertexArraysAPPLE: get_func(egl, "glGenVertexArraysAPPLE", &opengl_lib),
            glGenerateMipmap: get_func(egl, "glGenerateMipmap", &opengl_lib),
            glGetActiveAttrib: get_func(egl, "glGetActiveAttrib", &opengl_lib),
            glGetActiveUniform: get_func(egl, "glGetActiveUniform", &opengl_lib),
            glGetActiveUniformBlockName: get_func(egl, "glGetActiveUniformBlockName", &opengl_lib),
            glGetActiveUniformBlockiv: get_func(egl, "glGetActiveUniformBlockiv", &opengl_lib),
            glGetActiveUniformName: get_func(egl, "glGetActiveUniformName", &opengl_lib),
            glGetActiveUniformsiv: get_func(egl, "glGetActiveUniformsiv", &opengl_lib),
            glGetAttachedShaders: get_func(egl, "glGetAttachedShaders", &opengl_lib),
            glGetAttribLocation: get_func(egl, "glGetAttribLocation", &opengl_lib),
            glGetBooleani_v: get_func(egl, "glGetBooleani_v", &opengl_lib),
            glGetBooleanv: get_func(egl, "glGetBooleanv", &opengl_lib),
            glGetBufferParameteri64v: get_func(egl, "glGetBufferParameteri64v", &opengl_lib),
            glGetBufferParameteriv: get_func(egl, "glGetBufferParameteriv", &opengl_lib),
            glGetBufferPointerv: get_func(egl, "glGetBufferPointerv", &opengl_lib),
            glGetBufferSubData: get_func(egl, "glGetBufferSubData", &opengl_lib),
            glGetClipPlane: get_func(egl, "glGetClipPlane", &opengl_lib),
            glGetCompressedTexImage: get_func(egl, "glGetCompressedTexImage", &opengl_lib),
            glGetDebugMessageLog: get_func(egl, "glGetDebugMessageLog", &opengl_lib),
            glGetDebugMessageLogKHR: get_func(egl, "glGetDebugMessageLogKHR", &opengl_lib),
            glGetDoublev: get_func(egl, "glGetDoublev", &opengl_lib),
            glGetError: get_func(egl, "glGetError", &opengl_lib),
            glGetFloatv: get_func(egl, "glGetFloatv", &opengl_lib),
            glGetFragDataIndex: get_func(egl, "glGetFragDataIndex", &opengl_lib),
            glGetFragDataLocation: get_func(egl, "glGetFragDataLocation", &opengl_lib),
            glGetFramebufferAttachmentParameteriv: get_func(
                egl,
                "glGetFramebufferAttachmentParameteriv",
                &opengl_lib,
            ),
            glGetInteger64i_v: get_func(egl, "glGetInteger64i_v", &opengl_lib),
            glGetInteger64v: get_func(egl, "glGetInteger64v", &opengl_lib),
            glGetIntegeri_v: get_func(egl, "glGetIntegeri_v", &opengl_lib),
            glGetIntegerv: get_func(egl, "glGetIntegerv", &opengl_lib),
            glGetLightfv: get_func(egl, "glGetLightfv", &opengl_lib),
            glGetLightiv: get_func(egl, "glGetLightiv", &opengl_lib),
            glGetMapdv: get_func(egl, "glGetMapdv", &opengl_lib),
            glGetMapfv: get_func(egl, "glGetMapfv", &opengl_lib),
            glGetMapiv: get_func(egl, "glGetMapiv", &opengl_lib),
            glGetMaterialfv: get_func(egl, "glGetMaterialfv", &opengl_lib),
            glGetMaterialiv: get_func(egl, "glGetMaterialiv", &opengl_lib),
            glGetMultisamplefv: get_func(egl, "glGetMultisamplefv", &opengl_lib),
            glGetObjectLabel: get_func(egl, "glGetObjectLabel", &opengl_lib),
            glGetObjectLabelKHR: get_func(egl, "glGetObjectLabelKHR", &opengl_lib),
            glGetObjectPtrLabel: get_func(egl, "glGetObjectPtrLabel", &opengl_lib),
            glGetObjectPtrLabelKHR: get_func(egl, "glGetObjectPtrLabelKHR", &opengl_lib),
            glGetPixelMapfv: get_func(egl, "glGetPixelMapfv", &opengl_lib),
            glGetPixelMapuiv: get_func(egl, "glGetPixelMapuiv", &opengl_lib),
            glGetPixelMapusv: get_func(egl, "glGetPixelMapusv", &opengl_lib),
            glGetPointerv: get_func(egl, "glGetPointerv", &opengl_lib),
            glGetPointervKHR: get_func(egl, "glGetPointervKHR", &opengl_lib),
            glGetPolygonStipple: get_func(egl, "glGetPolygonStipple", &opengl_lib),
            glGetProgramBinary: get_func(egl, "glGetProgramBinary", &opengl_lib),
            glGetProgramInfoLog: get_func(egl, "glGetProgramInfoLog", &opengl_lib),
            glGetProgramiv: get_func(egl, "glGetProgramiv", &opengl_lib),
            glGetQueryObjecti64v: get_func(egl, "glGetQueryObjecti64v", &opengl_lib),
            glGetQueryObjectiv: get_func(egl, "glGetQueryObjectiv", &opengl_lib),
            glGetQueryObjectui64v: get_func(egl, "glGetQueryObjectui64v", &opengl_lib),
            glGetQueryObjectuiv: get_func(egl, "glGetQueryObjectuiv", &opengl_lib),
            glGetQueryiv: get_func(egl, "glGetQueryiv", &opengl_lib),
            glGetRenderbufferParameteriv: get_func(
                egl,
                "glGetRenderbufferParameteriv",
                &opengl_lib,
            ),
            glGetSamplerParameterIiv: get_func(egl, "glGetSamplerParameterIiv", &opengl_lib),
            glGetSamplerParameterIuiv: get_func(egl, "glGetSamplerParameterIuiv", &opengl_lib),
            glGetSamplerParameterfv: get_func(egl, "glGetSamplerParameterfv", &opengl_lib),
            glGetSamplerParameteriv: get_func(egl, "glGetSamplerParameteriv", &opengl_lib),
            glGetShaderInfoLog: get_func(egl, "glGetShaderInfoLog", &opengl_lib),
            glGetShaderSource: get_func(egl, "glGetShaderSource", &opengl_lib),
            glGetShaderiv: get_func(egl, "glGetShaderiv", &opengl_lib),
            glGetString: get_func(egl, "glGetString", &opengl_lib),
            glGetStringi: get_func(egl, "glGetStringi", &opengl_lib),
            glGetSynciv: get_func(egl, "glGetSynciv", &opengl_lib),
            glGetTexEnvfv: get_func(egl, "glGetTexEnvfv", &opengl_lib),
            glGetTexEnviv: get_func(egl, "glGetTexEnviv", &opengl_lib),
            glGetTexGendv: get_func(egl, "glGetTexGendv", &opengl_lib),
            glGetTexGenfv: get_func(egl, "glGetTexGenfv", &opengl_lib),
            glGetTexGeniv: get_func(egl, "glGetTexGeniv", &opengl_lib),
            glGetTexImage: get_func(egl, "glGetTexImage", &opengl_lib),
            glGetTexLevelParameterfv: get_func(egl, "glGetTexLevelParameterfv", &opengl_lib),
            glGetTexLevelParameteriv: get_func(egl, "glGetTexLevelParameteriv", &opengl_lib),
            glGetTexParameterIiv: get_func(egl, "glGetTexParameterIiv", &opengl_lib),
            glGetTexParameterIuiv: get_func(egl, "glGetTexParameterIuiv", &opengl_lib),
            glGetTexParameterPointervAPPLE: get_func(
                egl,
                "glGetTexParameterPointervAPPLE",
                &opengl_lib,
            ),
            glGetTexParameterfv: get_func(egl, "glGetTexParameterfv", &opengl_lib),
            glGetTexParameteriv: get_func(egl, "glGetTexParameteriv", &opengl_lib),
            glGetTransformFeedbackVarying: get_func(
                egl,
                "glGetTransformFeedbackVarying",
                &opengl_lib,
            ),
            glGetUniformBlockIndex: get_func(egl, "glGetUniformBlockIndex", &opengl_lib),
            glGetUniformIndices: get_func(egl, "glGetUniformIndices", &opengl_lib),
            glGetUniformLocation: get_func(egl, "glGetUniformLocation", &opengl_lib),
            glGetUniformfv: get_func(egl, "glGetUniformfv", &opengl_lib),
            glGetUniformiv: get_func(egl, "glGetUniformiv", &opengl_lib),
            glGetUniformuiv: get_func(egl, "glGetUniformuiv", &opengl_lib),
            glGetVertexAttribIiv: get_func(egl, "glGetVertexAttribIiv", &opengl_lib),
            glGetVertexAttribIuiv: get_func(egl, "glGetVertexAttribIuiv", &opengl_lib),
            glGetVertexAttribPointerv: get_func(egl, "glGetVertexAttribPointerv", &opengl_lib),
            glGetVertexAttribdv: get_func(egl, "glGetVertexAttribdv", &opengl_lib),
            glGetVertexAttribfv: get_func(egl, "glGetVertexAttribfv", &opengl_lib),
            glGetVertexAttribiv: get_func(egl, "glGetVertexAttribiv", &opengl_lib),
            glHint: get_func(egl, "glHint", &opengl_lib),
            glIndexMask: get_func(egl, "glIndexMask", &opengl_lib),
            glIndexPointer: get_func(egl, "glIndexPointer", &opengl_lib),
            glIndexd: get_func(egl, "glIndexd", &opengl_lib),
            glIndexdv: get_func(egl, "glIndexdv", &opengl_lib),
            glIndexf: get_func(egl, "glIndexf", &opengl_lib),
            glIndexfv: get_func(egl, "glIndexfv", &opengl_lib),
            glIndexi: get_func(egl, "glIndexi", &opengl_lib),
            glIndexiv: get_func(egl, "glIndexiv", &opengl_lib),
            glIndexs: get_func(egl, "glIndexs", &opengl_lib),
            glIndexsv: get_func(egl, "glIndexsv", &opengl_lib),
            glIndexub: get_func(egl, "glIndexub", &opengl_lib),
            glIndexubv: get_func(egl, "glIndexubv", &opengl_lib),
            glInitNames: get_func(egl, "glInitNames", &opengl_lib),
            glInsertEventMarkerEXT: get_func(egl, "glInsertEventMarkerEXT", &opengl_lib),
            glInterleavedArrays: get_func(egl, "glInterleavedArrays", &opengl_lib),
            glInvalidateBufferData: get_func(egl, "glInvalidateBufferData", &opengl_lib),
            glInvalidateBufferSubData: get_func(egl, "glInvalidateBufferSubData", &opengl_lib),
            glInvalidateFramebuffer: get_func(egl, "glInvalidateFramebuffer", &opengl_lib),
            glInvalidateSubFramebuffer: get_func(egl, "glInvalidateSubFramebuffer", &opengl_lib),
            glInvalidateTexImage: get_func(egl, "glInvalidateTexImage", &opengl_lib),
            glInvalidateTexSubImage: get_func(egl, "glInvalidateTexSubImage", &opengl_lib),
            glIsBuffer: get_func(egl, "glIsBuffer", &opengl_lib),
            glIsEnabled: get_func(egl, "glIsEnabled", &opengl_lib),
            glIsEnabledi: get_func(egl, "glIsEnabledi", &opengl_lib),
            glIsFenceAPPLE: get_func(egl, "glIsFenceAPPLE", &opengl_lib),
            glIsFramebuffer: get_func(egl, "glIsFramebuffer", &opengl_lib),
            glIsList: get_func(egl, "glIsList", &opengl_lib),
            glIsProgram: get_func(egl, "glIsProgram", &opengl_lib),
            glIsQuery: get_func(egl, "glIsQuery", &opengl_lib),
            glIsRenderbuffer: get_func(egl, "glIsRenderbuffer", &opengl_lib),
            glIsSampler: get_func(egl, "glIsSampler", &opengl_lib),
            glIsShader: get_func(egl, "glIsShader", &opengl_lib),
            glIsSync: get_func(egl, "glIsSync", &opengl_lib),
            glIsTexture: get_func(egl, "glIsTexture", &opengl_lib),
            glIsVertexArray: get_func(egl, "glIsVertexArray", &opengl_lib),
            glIsVertexArrayAPPLE: get_func(egl, "glIsVertexArrayAPPLE", &opengl_lib),
            glLightModelf: get_func(egl, "glLightModelf", &opengl_lib),
            glLightModelfv: get_func(egl, "glLightModelfv", &opengl_lib),
            glLightModeli: get_func(egl, "glLightModeli", &opengl_lib),
            glLightModeliv: get_func(egl, "glLightModeliv", &opengl_lib),
            glLightf: get_func(egl, "glLightf", &opengl_lib),
            glLightfv: get_func(egl, "glLightfv", &opengl_lib),
            glLighti: get_func(egl, "glLighti", &opengl_lib),
            glLightiv: get_func(egl, "glLightiv", &opengl_lib),
            glLineStipple: get_func(egl, "glLineStipple", &opengl_lib),
            glLineWidth: get_func(egl, "glLineWidth", &opengl_lib),
            glLinkProgram: get_func(egl, "glLinkProgram", &opengl_lib),
            glListBase: get_func(egl, "glListBase", &opengl_lib),
            glLoadIdentity: get_func(egl, "glLoadIdentity", &opengl_lib),
            glLoadMatrixd: get_func(egl, "glLoadMatrixd", &opengl_lib),
            glLoadMatrixf: get_func(egl, "glLoadMatrixf", &opengl_lib),
            glLoadName: get_func(egl, "glLoadName", &opengl_lib),
            glLoadTransposeMatrixd: get_func(egl, "glLoadTransposeMatrixd", &opengl_lib),
            glLoadTransposeMatrixf: get_func(egl, "glLoadTransposeMatrixf", &opengl_lib),
            glLogicOp: get_func(egl, "glLogicOp", &opengl_lib),
            glMap1d: get_func(egl, "glMap1d", &opengl_lib),
            glMap1f: get_func(egl, "glMap1f", &opengl_lib),
            glMap2d: get_func(egl, "glMap2d", &opengl_lib),
            glMap2f: get_func(egl, "glMap2f", &opengl_lib),
            glMapBuffer: get_func(egl, "glMapBuffer", &opengl_lib),
            glMapBufferRange: get_func(egl, "glMapBufferRange", &opengl_lib),
            glMapGrid1d: get_func(egl, "glMapGrid1d", &opengl_lib),
            glMapGrid1f: get_func(egl, "glMapGrid1f", &opengl_lib),
            glMapGrid2d: get_func(egl, "glMapGrid2d", &opengl_lib),
            glMapGrid2f: get_func(egl, "glMapGrid2f", &opengl_lib),
            glMaterialf: get_func(egl, "glMaterialf", &opengl_lib),
            glMaterialfv: get_func(egl, "glMaterialfv", &opengl_lib),
            glMateriali: get_func(egl, "glMateriali", &opengl_lib),
            glMaterialiv: get_func(egl, "glMaterialiv", &opengl_lib),
            glMatrixMode: get_func(egl, "glMatrixMode", &opengl_lib),
            glMultMatrixd: get_func(egl, "glMultMatrixd", &opengl_lib),
            glMultMatrixf: get_func(egl, "glMultMatrixf", &opengl_lib),
            glMultTransposeMatrixd: get_func(egl, "glMultTransposeMatrixd", &opengl_lib),
            glMultTransposeMatrixf: get_func(egl, "glMultTransposeMatrixf", &opengl_lib),
            glMultiDrawArrays: get_func(egl, "glMultiDrawArrays", &opengl_lib),
            glMultiDrawElements: get_func(egl, "glMultiDrawElements", &opengl_lib),
            glMultiDrawElementsBaseVertex: get_func(
                egl,
                "glMultiDrawElementsBaseVertex",
                &opengl_lib,
            ),
            glMultiTexCoord1d: get_func(egl, "glMultiTexCoord1d", &opengl_lib),
            glMultiTexCoord1dv: get_func(egl, "glMultiTexCoord1dv", &opengl_lib),
            glMultiTexCoord1f: get_func(egl, "glMultiTexCoord1f", &opengl_lib),
            glMultiTexCoord1fv: get_func(egl, "glMultiTexCoord1fv", &opengl_lib),
            glMultiTexCoord1i: get_func(egl, "glMultiTexCoord1i", &opengl_lib),
            glMultiTexCoord1iv: get_func(egl, "glMultiTexCoord1iv", &opengl_lib),
            glMultiTexCoord1s: get_func(egl, "glMultiTexCoord1s", &opengl_lib),
            glMultiTexCoord1sv: get_func(egl, "glMultiTexCoord1sv", &opengl_lib),
            glMultiTexCoord2d: get_func(egl, "glMultiTexCoord2d", &opengl_lib),
            glMultiTexCoord2dv: get_func(egl, "glMultiTexCoord2dv", &opengl_lib),
            glMultiTexCoord2f: get_func(egl, "glMultiTexCoord2f", &opengl_lib),
            glMultiTexCoord2fv: get_func(egl, "glMultiTexCoord2fv", &opengl_lib),
            glMultiTexCoord2i: get_func(egl, "glMultiTexCoord2i", &opengl_lib),
            glMultiTexCoord2iv: get_func(egl, "glMultiTexCoord2iv", &opengl_lib),
            glMultiTexCoord2s: get_func(egl, "glMultiTexCoord2s", &opengl_lib),
            glMultiTexCoord2sv: get_func(egl, "glMultiTexCoord2sv", &opengl_lib),
            glMultiTexCoord3d: get_func(egl, "glMultiTexCoord3d", &opengl_lib),
            glMultiTexCoord3dv: get_func(egl, "glMultiTexCoord3dv", &opengl_lib),
            glMultiTexCoord3f: get_func(egl, "glMultiTexCoord3f", &opengl_lib),
            glMultiTexCoord3fv: get_func(egl, "glMultiTexCoord3fv", &opengl_lib),
            glMultiTexCoord3i: get_func(egl, "glMultiTexCoord3i", &opengl_lib),
            glMultiTexCoord3iv: get_func(egl, "glMultiTexCoord3iv", &opengl_lib),
            glMultiTexCoord3s: get_func(egl, "glMultiTexCoord3s", &opengl_lib),
            glMultiTexCoord3sv: get_func(egl, "glMultiTexCoord3sv", &opengl_lib),
            glMultiTexCoord4d: get_func(egl, "glMultiTexCoord4d", &opengl_lib),
            glMultiTexCoord4dv: get_func(egl, "glMultiTexCoord4dv", &opengl_lib),
            glMultiTexCoord4f: get_func(egl, "glMultiTexCoord4f", &opengl_lib),
            glMultiTexCoord4fv: get_func(egl, "glMultiTexCoord4fv", &opengl_lib),
            glMultiTexCoord4i: get_func(egl, "glMultiTexCoord4i", &opengl_lib),
            glMultiTexCoord4iv: get_func(egl, "glMultiTexCoord4iv", &opengl_lib),
            glMultiTexCoord4s: get_func(egl, "glMultiTexCoord4s", &opengl_lib),
            glMultiTexCoord4sv: get_func(egl, "glMultiTexCoord4sv", &opengl_lib),
            glMultiTexCoordP1ui: get_func(egl, "glMultiTexCoordP1ui", &opengl_lib),
            glMultiTexCoordP1uiv: get_func(egl, "glMultiTexCoordP1uiv", &opengl_lib),
            glMultiTexCoordP2ui: get_func(egl, "glMultiTexCoordP2ui", &opengl_lib),
            glMultiTexCoordP2uiv: get_func(egl, "glMultiTexCoordP2uiv", &opengl_lib),
            glMultiTexCoordP3ui: get_func(egl, "glMultiTexCoordP3ui", &opengl_lib),
            glMultiTexCoordP3uiv: get_func(egl, "glMultiTexCoordP3uiv", &opengl_lib),
            glMultiTexCoordP4ui: get_func(egl, "glMultiTexCoordP4ui", &opengl_lib),
            glMultiTexCoordP4uiv: get_func(egl, "glMultiTexCoordP4uiv", &opengl_lib),
            glNewList: get_func(egl, "glNewList", &opengl_lib),
            glNormal3b: get_func(egl, "glNormal3b", &opengl_lib),
            glNormal3bv: get_func(egl, "glNormal3bv", &opengl_lib),
            glNormal3d: get_func(egl, "glNormal3d", &opengl_lib),
            glNormal3dv: get_func(egl, "glNormal3dv", &opengl_lib),
            glNormal3f: get_func(egl, "glNormal3f", &opengl_lib),
            glNormal3fv: get_func(egl, "glNormal3fv", &opengl_lib),
            glNormal3i: get_func(egl, "glNormal3i", &opengl_lib),
            glNormal3iv: get_func(egl, "glNormal3iv", &opengl_lib),
            glNormal3s: get_func(egl, "glNormal3s", &opengl_lib),
            glNormal3sv: get_func(egl, "glNormal3sv", &opengl_lib),
            glNormalP3ui: get_func(egl, "glNormalP3ui", &opengl_lib),
            glNormalP3uiv: get_func(egl, "glNormalP3uiv", &opengl_lib),
            glNormalPointer: get_func(egl, "glNormalPointer", &opengl_lib),
            glObjectLabel: get_func(egl, "glObjectLabel", &opengl_lib),
            glObjectLabelKHR: get_func(egl, "glObjectLabelKHR", &opengl_lib),
            glObjectPtrLabel: get_func(egl, "glObjectPtrLabel", &opengl_lib),
            glObjectPtrLabelKHR: get_func(egl, "glObjectPtrLabelKHR", &opengl_lib),
            glOrtho: get_func(egl, "glOrtho", &opengl_lib),
            glPassThrough: get_func(egl, "glPassThrough", &opengl_lib),
            glPixelMapfv: get_func(egl, "glPixelMapfv", &opengl_lib),
            glPixelMapuiv: get_func(egl, "glPixelMapuiv", &opengl_lib),
            glPixelMapusv: get_func(egl, "glPixelMapusv", &opengl_lib),
            glPixelStoref: get_func(egl, "glPixelStoref", &opengl_lib),
            glPixelStorei: get_func(egl, "glPixelStorei", &opengl_lib),
            glPixelTransferf: get_func(egl, "glPixelTransferf", &opengl_lib),
            glPixelTransferi: get_func(egl, "glPixelTransferi", &opengl_lib),
            glPixelZoom: get_func(egl, "glPixelZoom", &opengl_lib),
            glPointParameterf: get_func(egl, "glPointParameterf", &opengl_lib),
            glPointParameterfv: get_func(egl, "glPointParameterfv", &opengl_lib),
            glPointParameteri: get_func(egl, "glPointParameteri", &opengl_lib),
            glPointParameteriv: get_func(egl, "glPointParameteriv", &opengl_lib),
            glPointSize: get_func(egl, "glPointSize", &opengl_lib),
            glPolygonMode: get_func(egl, "glPolygonMode", &opengl_lib),
            glPolygonOffset: get_func(egl, "glPolygonOffset", &opengl_lib),
            glPolygonStipple: get_func(egl, "glPolygonStipple", &opengl_lib),
            glPopAttrib: get_func(egl, "glPopAttrib", &opengl_lib),
            glPopClientAttrib: get_func(egl, "glPopClientAttrib", &opengl_lib),
            glPopDebugGroup: get_func(egl, "glPopDebugGroup", &opengl_lib),
            glPopDebugGroupKHR: get_func(egl, "glPopDebugGroupKHR", &opengl_lib),
            glPopGroupMarkerEXT: get_func(egl, "glPopGroupMarkerEXT", &opengl_lib),
            glPopMatrix: get_func(egl, "glPopMatrix", &opengl_lib),
            glPopName: get_func(egl, "glPopName", &opengl_lib),
            glPrimitiveRestartIndex: get_func(egl, "glPrimitiveRestartIndex", &opengl_lib),
            glPrioritizeTextures: get_func(egl, "glPrioritizeTextures", &opengl_lib),
            glProgramBinary: get_func(egl, "glProgramBinary", &opengl_lib),
            glProgramParameteri: get_func(egl, "glProgramParameteri", &opengl_lib),
            glProvokingVertex: get_func(egl, "glProvokingVertex", &opengl_lib),
            glPushAttrib: get_func(egl, "glPushAttrib", &opengl_lib),
            glPushClientAttrib: get_func(egl, "glPushClientAttrib", &opengl_lib),
            glPushDebugGroup: get_func(egl, "glPushDebugGroup", &opengl_lib),
            glPushDebugGroupKHR: get_func(egl, "glPushDebugGroupKHR", &opengl_lib),
            glPushGroupMarkerEXT: get_func(egl, "glPushGroupMarkerEXT", &opengl_lib),
            glPushMatrix: get_func(egl, "glPushMatrix", &opengl_lib),
            glPushName: get_func(egl, "glPushName", &opengl_lib),
            glQueryCounter: get_func(egl, "glQueryCounter", &opengl_lib),
            glRasterPos2d: get_func(egl, "glRasterPos2d", &opengl_lib),
            glRasterPos2dv: get_func(egl, "glRasterPos2dv", &opengl_lib),
            glRasterPos2f: get_func(egl, "glRasterPos2f", &opengl_lib),
            glRasterPos2fv: get_func(egl, "glRasterPos2fv", &opengl_lib),
            glRasterPos2i: get_func(egl, "glRasterPos2i", &opengl_lib),
            glRasterPos2iv: get_func(egl, "glRasterPos2iv", &opengl_lib),
            glRasterPos2s: get_func(egl, "glRasterPos2s", &opengl_lib),
            glRasterPos2sv: get_func(egl, "glRasterPos2sv", &opengl_lib),
            glRasterPos3d: get_func(egl, "glRasterPos3d", &opengl_lib),
            glRasterPos3dv: get_func(egl, "glRasterPos3dv", &opengl_lib),
            glRasterPos3f: get_func(egl, "glRasterPos3f", &opengl_lib),
            glRasterPos3fv: get_func(egl, "glRasterPos3fv", &opengl_lib),
            glRasterPos3i: get_func(egl, "glRasterPos3i", &opengl_lib),
            glRasterPos3iv: get_func(egl, "glRasterPos3iv", &opengl_lib),
            glRasterPos3s: get_func(egl, "glRasterPos3s", &opengl_lib),
            glRasterPos3sv: get_func(egl, "glRasterPos3sv", &opengl_lib),
            glRasterPos4d: get_func(egl, "glRasterPos4d", &opengl_lib),
            glRasterPos4dv: get_func(egl, "glRasterPos4dv", &opengl_lib),
            glRasterPos4f: get_func(egl, "glRasterPos4f", &opengl_lib),
            glRasterPos4fv: get_func(egl, "glRasterPos4fv", &opengl_lib),
            glRasterPos4i: get_func(egl, "glRasterPos4i", &opengl_lib),
            glRasterPos4iv: get_func(egl, "glRasterPos4iv", &opengl_lib),
            glRasterPos4s: get_func(egl, "glRasterPos4s", &opengl_lib),
            glRasterPos4sv: get_func(egl, "glRasterPos4sv", &opengl_lib),
            glReadBuffer: get_func(egl, "glReadBuffer", &opengl_lib),
            glReadPixels: get_func(egl, "glReadPixels", &opengl_lib),
            glRectd: get_func(egl, "glRectd", &opengl_lib),
            glRectdv: get_func(egl, "glRectdv", &opengl_lib),
            glRectf: get_func(egl, "glRectf", &opengl_lib),
            glRectfv: get_func(egl, "glRectfv", &opengl_lib),
            glRecti: get_func(egl, "glRecti", &opengl_lib),
            glRectiv: get_func(egl, "glRectiv", &opengl_lib),
            glRects: get_func(egl, "glRects", &opengl_lib),
            glRectsv: get_func(egl, "glRectsv", &opengl_lib),
            glRenderMode: get_func(egl, "glRenderMode", &opengl_lib),
            glRenderbufferStorage: get_func(egl, "glRenderbufferStorage", &opengl_lib),
            glRenderbufferStorageMultisample: get_func(
                egl,
                "glRenderbufferStorageMultisample",
                &opengl_lib,
            ),
            glRotated: get_func(egl, "glRotated", &opengl_lib),
            glRotatef: get_func(egl, "glRotatef", &opengl_lib),
            glSampleCoverage: get_func(egl, "glSampleCoverage", &opengl_lib),
            glSampleMaski: get_func(egl, "glSampleMaski", &opengl_lib),
            glSamplerParameterIiv: get_func(egl, "glSamplerParameterIiv", &opengl_lib),
            glSamplerParameterIuiv: get_func(egl, "glSamplerParameterIuiv", &opengl_lib),
            glSamplerParameterf: get_func(egl, "glSamplerParameterf", &opengl_lib),
            glSamplerParameterfv: get_func(egl, "glSamplerParameterfv", &opengl_lib),
            glSamplerParameteri: get_func(egl, "glSamplerParameteri", &opengl_lib),
            glSamplerParameteriv: get_func(egl, "glSamplerParameteriv", &opengl_lib),
            glScaled: get_func(egl, "glScaled", &opengl_lib),
            glScalef: get_func(egl, "glScalef", &opengl_lib),
            glScissor: get_func(egl, "glScissor", &opengl_lib),
            glSecondaryColor3b: get_func(egl, "glSecondaryColor3b", &opengl_lib),
            glSecondaryColor3bv: get_func(egl, "glSecondaryColor3bv", &opengl_lib),
            glSecondaryColor3d: get_func(egl, "glSecondaryColor3d", &opengl_lib),
            glSecondaryColor3dv: get_func(egl, "glSecondaryColor3dv", &opengl_lib),
            glSecondaryColor3f: get_func(egl, "glSecondaryColor3f", &opengl_lib),
            glSecondaryColor3fv: get_func(egl, "glSecondaryColor3fv", &opengl_lib),
            glSecondaryColor3i: get_func(egl, "glSecondaryColor3i", &opengl_lib),
            glSecondaryColor3iv: get_func(egl, "glSecondaryColor3iv", &opengl_lib),
            glSecondaryColor3s: get_func(egl, "glSecondaryColor3s", &opengl_lib),
            glSecondaryColor3sv: get_func(egl, "glSecondaryColor3sv", &opengl_lib),
            glSecondaryColor3ub: get_func(egl, "glSecondaryColor3ub", &opengl_lib),
            glSecondaryColor3ubv: get_func(egl, "glSecondaryColor3ubv", &opengl_lib),
            glSecondaryColor3ui: get_func(egl, "glSecondaryColor3ui", &opengl_lib),
            glSecondaryColor3uiv: get_func(egl, "glSecondaryColor3uiv", &opengl_lib),
            glSecondaryColor3us: get_func(egl, "glSecondaryColor3us", &opengl_lib),
            glSecondaryColor3usv: get_func(egl, "glSecondaryColor3usv", &opengl_lib),
            glSecondaryColorP3ui: get_func(egl, "glSecondaryColorP3ui", &opengl_lib),
            glSecondaryColorP3uiv: get_func(egl, "glSecondaryColorP3uiv", &opengl_lib),
            glSecondaryColorPointer: get_func(egl, "glSecondaryColorPointer", &opengl_lib),
            glSelectBuffer: get_func(egl, "glSelectBuffer", &opengl_lib),
            glSetFenceAPPLE: get_func(egl, "glSetFenceAPPLE", &opengl_lib),
            glShadeModel: get_func(egl, "glShadeModel", &opengl_lib),
            glShaderSource: get_func(egl, "glShaderSource", &opengl_lib),
            glShaderStorageBlockBinding: get_func(egl, "glShaderStorageBlockBinding", &opengl_lib),
            glStencilFunc: get_func(egl, "glStencilFunc", &opengl_lib),
            glStencilFuncSeparate: get_func(egl, "glStencilFuncSeparate", &opengl_lib),
            glStencilMask: get_func(egl, "glStencilMask", &opengl_lib),
            glStencilMaskSeparate: get_func(egl, "glStencilMaskSeparate", &opengl_lib),
            glStencilOp: get_func(egl, "glStencilOp", &opengl_lib),
            glStencilOpSeparate: get_func(egl, "glStencilOpSeparate", &opengl_lib),
            glTestFenceAPPLE: get_func(egl, "glTestFenceAPPLE", &opengl_lib),
            glTestObjectAPPLE: get_func(egl, "glTestObjectAPPLE", &opengl_lib),
            glTexBuffer: get_func(egl, "glTexBuffer", &opengl_lib),
            glTexCoord1d: get_func(egl, "glTexCoord1d", &opengl_lib),
            glTexCoord1dv: get_func(egl, "glTexCoord1dv", &opengl_lib),
            glTexCoord1f: get_func(egl, "glTexCoord1f", &opengl_lib),
            glTexCoord1fv: get_func(egl, "glTexCoord1fv", &opengl_lib),
            glTexCoord1i: get_func(egl, "glTexCoord1i", &opengl_lib),
            glTexCoord1iv: get_func(egl, "glTexCoord1iv", &opengl_lib),
            glTexCoord1s: get_func(egl, "glTexCoord1s", &opengl_lib),
            glTexCoord1sv: get_func(egl, "glTexCoord1sv", &opengl_lib),
            glTexCoord2d: get_func(egl, "glTexCoord2d", &opengl_lib),
            glTexCoord2dv: get_func(egl, "glTexCoord2dv", &opengl_lib),
            glTexCoord2f: get_func(egl, "glTexCoord2f", &opengl_lib),
            glTexCoord2fv: get_func(egl, "glTexCoord2fv", &opengl_lib),
            glTexCoord2i: get_func(egl, "glTexCoord2i", &opengl_lib),
            glTexCoord2iv: get_func(egl, "glTexCoord2iv", &opengl_lib),
            glTexCoord2s: get_func(egl, "glTexCoord2s", &opengl_lib),
            glTexCoord2sv: get_func(egl, "glTexCoord2sv", &opengl_lib),
            glTexCoord3d: get_func(egl, "glTexCoord3d", &opengl_lib),
            glTexCoord3dv: get_func(egl, "glTexCoord3dv", &opengl_lib),
            glTexCoord3f: get_func(egl, "glTexCoord3f", &opengl_lib),
            glTexCoord3fv: get_func(egl, "glTexCoord3fv", &opengl_lib),
            glTexCoord3i: get_func(egl, "glTexCoord3i", &opengl_lib),
            glTexCoord3iv: get_func(egl, "glTexCoord3iv", &opengl_lib),
            glTexCoord3s: get_func(egl, "glTexCoord3s", &opengl_lib),
            glTexCoord3sv: get_func(egl, "glTexCoord3sv", &opengl_lib),
            glTexCoord4d: get_func(egl, "glTexCoord4d", &opengl_lib),
            glTexCoord4dv: get_func(egl, "glTexCoord4dv", &opengl_lib),
            glTexCoord4f: get_func(egl, "glTexCoord4f", &opengl_lib),
            glTexCoord4fv: get_func(egl, "glTexCoord4fv", &opengl_lib),
            glTexCoord4i: get_func(egl, "glTexCoord4i", &opengl_lib),
            glTexCoord4iv: get_func(egl, "glTexCoord4iv", &opengl_lib),
            glTexCoord4s: get_func(egl, "glTexCoord4s", &opengl_lib),
            glTexCoord4sv: get_func(egl, "glTexCoord4sv", &opengl_lib),
            glTexCoordP1ui: get_func(egl, "glTexCoordP1ui", &opengl_lib),
            glTexCoordP1uiv: get_func(egl, "glTexCoordP1uiv", &opengl_lib),
            glTexCoordP2ui: get_func(egl, "glTexCoordP2ui", &opengl_lib),
            glTexCoordP2uiv: get_func(egl, "glTexCoordP2uiv", &opengl_lib),
            glTexCoordP3ui: get_func(egl, "glTexCoordP3ui", &opengl_lib),
            glTexCoordP3uiv: get_func(egl, "glTexCoordP3uiv", &opengl_lib),
            glTexCoordP4ui: get_func(egl, "glTexCoordP4ui", &opengl_lib),
            glTexCoordP4uiv: get_func(egl, "glTexCoordP4uiv", &opengl_lib),
            glTexCoordPointer: get_func(egl, "glTexCoordPointer", &opengl_lib),
            glTexEnvf: get_func(egl, "glTexEnvf", &opengl_lib),
            glTexEnvfv: get_func(egl, "glTexEnvfv", &opengl_lib),
            glTexEnvi: get_func(egl, "glTexEnvi", &opengl_lib),
            glTexEnviv: get_func(egl, "glTexEnviv", &opengl_lib),
            glTexGend: get_func(egl, "glTexGend", &opengl_lib),
            glTexGendv: get_func(egl, "glTexGendv", &opengl_lib),
            glTexGenf: get_func(egl, "glTexGenf", &opengl_lib),
            glTexGenfv: get_func(egl, "glTexGenfv", &opengl_lib),
            glTexGeni: get_func(egl, "glTexGeni", &opengl_lib),
            glTexGeniv: get_func(egl, "glTexGeniv", &opengl_lib),
            glTexImage1D: get_func(egl, "glTexImage1D", &opengl_lib),
            glTexImage2D: get_func(egl, "glTexImage2D", &opengl_lib),
            glTexImage2DMultisample: get_func(egl, "glTexImage2DMultisample", &opengl_lib),
            glTexImage3D: get_func(egl, "glTexImage3D", &opengl_lib),
            glTexImage3DMultisample: get_func(egl, "glTexImage3DMultisample", &opengl_lib),
            glTexParameterIiv: get_func(egl, "glTexParameterIiv", &opengl_lib),
            glTexParameterIuiv: get_func(egl, "glTexParameterIuiv", &opengl_lib),
            glTexParameterf: get_func(egl, "glTexParameterf", &opengl_lib),
            glTexParameterfv: get_func(egl, "glTexParameterfv", &opengl_lib),
            glTexParameteri: get_func(egl, "glTexParameteri", &opengl_lib),
            glTexParameteriv: get_func(egl, "glTexParameteriv", &opengl_lib),
            glTexStorage1D: get_func(egl, "glTexStorage1D", &opengl_lib),
            glTexStorage2D: get_func(egl, "glTexStorage2D", &opengl_lib),
            glTexStorage3D: get_func(egl, "glTexStorage3D", &opengl_lib),
            glTexSubImage1D: get_func(egl, "glTexSubImage1D", &opengl_lib),
            glTexSubImage2D: get_func(egl, "glTexSubImage2D", &opengl_lib),
            glTexSubImage3D: get_func(egl, "glTexSubImage3D", &opengl_lib),
            glTextureRangeAPPLE: get_func(egl, "glTextureRangeAPPLE", &opengl_lib),
            glTransformFeedbackVaryings: get_func(egl, "glTransformFeedbackVaryings", &opengl_lib),
            glTranslated: get_func(egl, "glTranslated", &opengl_lib),
            glTranslatef: get_func(egl, "glTranslatef", &opengl_lib),
            glUniform1f: get_func(egl, "glUniform1f", &opengl_lib),
            glUniform1fv: get_func(egl, "glUniform1fv", &opengl_lib),
            glUniform1i: get_func(egl, "glUniform1i", &opengl_lib),
            glUniform1iv: get_func(egl, "glUniform1iv", &opengl_lib),
            glUniform1ui: get_func(egl, "glUniform1ui", &opengl_lib),
            glUniform1uiv: get_func(egl, "glUniform1uiv", &opengl_lib),
            glUniform2f: get_func(egl, "glUniform2f", &opengl_lib),
            glUniform2fv: get_func(egl, "glUniform2fv", &opengl_lib),
            glUniform2i: get_func(egl, "glUniform2i", &opengl_lib),
            glUniform2iv: get_func(egl, "glUniform2iv", &opengl_lib),
            glUniform2ui: get_func(egl, "glUniform2ui", &opengl_lib),
            glUniform2uiv: get_func(egl, "glUniform2uiv", &opengl_lib),
            glUniform3f: get_func(egl, "glUniform3f", &opengl_lib),
            glUniform3fv: get_func(egl, "glUniform3fv", &opengl_lib),
            glUniform3i: get_func(egl, "glUniform3i", &opengl_lib),
            glUniform3iv: get_func(egl, "glUniform3iv", &opengl_lib),
            glUniform3ui: get_func(egl, "glUniform3ui", &opengl_lib),
            glUniform3uiv: get_func(egl, "glUniform3uiv", &opengl_lib),
            glUniform4f: get_func(egl, "glUniform4f", &opengl_lib),
            glUniform4fv: get_func(egl, "glUniform4fv", &opengl_lib),
            glUniform4i: get_func(egl, "glUniform4i", &opengl_lib),
            glUniform4iv: get_func(egl, "glUniform4iv", &opengl_lib),
            glUniform4ui: get_func(egl, "glUniform4ui", &opengl_lib),
            glUniform4uiv: get_func(egl, "glUniform4uiv", &opengl_lib),
            glUniformBlockBinding: get_func(egl, "glUniformBlockBinding", &opengl_lib),
            glUniformMatrix2fv: get_func(egl, "glUniformMatrix2fv", &opengl_lib),
            glUniformMatrix2x3fv: get_func(egl, "glUniformMatrix2x3fv", &opengl_lib),
            glUniformMatrix2x4fv: get_func(egl, "glUniformMatrix2x4fv", &opengl_lib),
            glUniformMatrix3fv: get_func(egl, "glUniformMatrix3fv", &opengl_lib),
            glUniformMatrix3x2fv: get_func(egl, "glUniformMatrix3x2fv", &opengl_lib),
            glUniformMatrix3x4fv: get_func(egl, "glUniformMatrix3x4fv", &opengl_lib),
            glUniformMatrix4fv: get_func(egl, "glUniformMatrix4fv", &opengl_lib),
            glUniformMatrix4x2fv: get_func(egl, "glUniformMatrix4x2fv", &opengl_lib),
            glUniformMatrix4x3fv: get_func(egl, "glUniformMatrix4x3fv", &opengl_lib),
            glUnmapBuffer: get_func(egl, "glUnmapBuffer", &opengl_lib),
            glUseProgram: get_func(egl, "glUseProgram", &opengl_lib),
            glValidateProgram: get_func(egl, "glValidateProgram", &opengl_lib),
            glVertex2d: get_func(egl, "glVertex2d", &opengl_lib),
            glVertex2dv: get_func(egl, "glVertex2dv", &opengl_lib),
            glVertex2f: get_func(egl, "glVertex2f", &opengl_lib),
            glVertex2fv: get_func(egl, "glVertex2fv", &opengl_lib),
            glVertex2i: get_func(egl, "glVertex2i", &opengl_lib),
            glVertex2iv: get_func(egl, "glVertex2iv", &opengl_lib),
            glVertex2s: get_func(egl, "glVertex2s", &opengl_lib),
            glVertex2sv: get_func(egl, "glVertex2sv", &opengl_lib),
            glVertex3d: get_func(egl, "glVertex3d", &opengl_lib),
            glVertex3dv: get_func(egl, "glVertex3dv", &opengl_lib),
            glVertex3f: get_func(egl, "glVertex3f", &opengl_lib),
            glVertex3fv: get_func(egl, "glVertex3fv", &opengl_lib),
            glVertex3i: get_func(egl, "glVertex3i", &opengl_lib),
            glVertex3iv: get_func(egl, "glVertex3iv", &opengl_lib),
            glVertex3s: get_func(egl, "glVertex3s", &opengl_lib),
            glVertex3sv: get_func(egl, "glVertex3sv", &opengl_lib),
            glVertex4d: get_func(egl, "glVertex4d", &opengl_lib),
            glVertex4dv: get_func(egl, "glVertex4dv", &opengl_lib),
            glVertex4f: get_func(egl, "glVertex4f", &opengl_lib),
            glVertex4fv: get_func(egl, "glVertex4fv", &opengl_lib),
            glVertex4i: get_func(egl, "glVertex4i", &opengl_lib),
            glVertex4iv: get_func(egl, "glVertex4iv", &opengl_lib),
            glVertex4s: get_func(egl, "glVertex4s", &opengl_lib),
            glVertex4sv: get_func(egl, "glVertex4sv", &opengl_lib),
            glVertexAttrib1d: get_func(egl, "glVertexAttrib1d", &opengl_lib),
            glVertexAttrib1dv: get_func(egl, "glVertexAttrib1dv", &opengl_lib),
            glVertexAttrib1f: get_func(egl, "glVertexAttrib1f", &opengl_lib),
            glVertexAttrib1fv: get_func(egl, "glVertexAttrib1fv", &opengl_lib),
            glVertexAttrib1s: get_func(egl, "glVertexAttrib1s", &opengl_lib),
            glVertexAttrib1sv: get_func(egl, "glVertexAttrib1sv", &opengl_lib),
            glVertexAttrib2d: get_func(egl, "glVertexAttrib2d", &opengl_lib),
            glVertexAttrib2dv: get_func(egl, "glVertexAttrib2dv", &opengl_lib),
            glVertexAttrib2f: get_func(egl, "glVertexAttrib2f", &opengl_lib),
            glVertexAttrib2fv: get_func(egl, "glVertexAttrib2fv", &opengl_lib),
            glVertexAttrib2s: get_func(egl, "glVertexAttrib2s", &opengl_lib),
            glVertexAttrib2sv: get_func(egl, "glVertexAttrib2sv", &opengl_lib),
            glVertexAttrib3d: get_func(egl, "glVertexAttrib3d", &opengl_lib),
            glVertexAttrib3dv: get_func(egl, "glVertexAttrib3dv", &opengl_lib),
            glVertexAttrib3f: get_func(egl, "glVertexAttrib3f", &opengl_lib),
            glVertexAttrib3fv: get_func(egl, "glVertexAttrib3fv", &opengl_lib),
            glVertexAttrib3s: get_func(egl, "glVertexAttrib3s", &opengl_lib),
            glVertexAttrib3sv: get_func(egl, "glVertexAttrib3sv", &opengl_lib),
            glVertexAttrib4Nbv: get_func(egl, "glVertexAttrib4Nbv", &opengl_lib),
            glVertexAttrib4Niv: get_func(egl, "glVertexAttrib4Niv", &opengl_lib),
            glVertexAttrib4Nsv: get_func(egl, "glVertexAttrib4Nsv", &opengl_lib),
            glVertexAttrib4Nub: get_func(egl, "glVertexAttrib4Nub", &opengl_lib),
            glVertexAttrib4Nubv: get_func(egl, "glVertexAttrib4Nubv", &opengl_lib),
            glVertexAttrib4Nuiv: get_func(egl, "glVertexAttrib4Nuiv", &opengl_lib),
            glVertexAttrib4Nusv: get_func(egl, "glVertexAttrib4Nusv", &opengl_lib),
            glVertexAttrib4bv: get_func(egl, "glVertexAttrib4bv", &opengl_lib),
            glVertexAttrib4d: get_func(egl, "glVertexAttrib4d", &opengl_lib),
            glVertexAttrib4dv: get_func(egl, "glVertexAttrib4dv", &opengl_lib),
            glVertexAttrib4f: get_func(egl, "glVertexAttrib4f", &opengl_lib),
            glVertexAttrib4fv: get_func(egl, "glVertexAttrib4fv", &opengl_lib),
            glVertexAttrib4iv: get_func(egl, "glVertexAttrib4iv", &opengl_lib),
            glVertexAttrib4s: get_func(egl, "glVertexAttrib4s", &opengl_lib),
            glVertexAttrib4sv: get_func(egl, "glVertexAttrib4sv", &opengl_lib),
            glVertexAttrib4ubv: get_func(egl, "glVertexAttrib4ubv", &opengl_lib),
            glVertexAttrib4uiv: get_func(egl, "glVertexAttrib4uiv", &opengl_lib),
            glVertexAttrib4usv: get_func(egl, "glVertexAttrib4usv", &opengl_lib),
            glVertexAttribDivisor: get_func(egl, "glVertexAttribDivisor", &opengl_lib),
            glVertexAttribI1i: get_func(egl, "glVertexAttribI1i", &opengl_lib),
            glVertexAttribI1iv: get_func(egl, "glVertexAttribI1iv", &opengl_lib),
            glVertexAttribI1ui: get_func(egl, "glVertexAttribI1ui", &opengl_lib),
            glVertexAttribI1uiv: get_func(egl, "glVertexAttribI1uiv", &opengl_lib),
            glVertexAttribI2i: get_func(egl, "glVertexAttribI2i", &opengl_lib),
            glVertexAttribI2iv: get_func(egl, "glVertexAttribI2iv", &opengl_lib),
            glVertexAttribI2ui: get_func(egl, "glVertexAttribI2ui", &opengl_lib),
            glVertexAttribI2uiv: get_func(egl, "glVertexAttribI2uiv", &opengl_lib),
            glVertexAttribI3i: get_func(egl, "glVertexAttribI3i", &opengl_lib),
            glVertexAttribI3iv: get_func(egl, "glVertexAttribI3iv", &opengl_lib),
            glVertexAttribI3ui: get_func(egl, "glVertexAttribI3ui", &opengl_lib),
            glVertexAttribI3uiv: get_func(egl, "glVertexAttribI3uiv", &opengl_lib),
            glVertexAttribI4bv: get_func(egl, "glVertexAttribI4bv", &opengl_lib),
            glVertexAttribI4i: get_func(egl, "glVertexAttribI4i", &opengl_lib),
            glVertexAttribI4iv: get_func(egl, "glVertexAttribI4iv", &opengl_lib),
            glVertexAttribI4sv: get_func(egl, "glVertexAttribI4sv", &opengl_lib),
            glVertexAttribI4ubv: get_func(egl, "glVertexAttribI4ubv", &opengl_lib),
            glVertexAttribI4ui: get_func(egl, "glVertexAttribI4ui", &opengl_lib),
            glVertexAttribI4uiv: get_func(egl, "glVertexAttribI4uiv", &opengl_lib),
            glVertexAttribI4usv: get_func(egl, "glVertexAttribI4usv", &opengl_lib),
            glVertexAttribIPointer: get_func(egl, "glVertexAttribIPointer", &opengl_lib),
            glVertexAttribP1ui: get_func(egl, "glVertexAttribP1ui", &opengl_lib),
            glVertexAttribP1uiv: get_func(egl, "glVertexAttribP1uiv", &opengl_lib),
            glVertexAttribP2ui: get_func(egl, "glVertexAttribP2ui", &opengl_lib),
            glVertexAttribP2uiv: get_func(egl, "glVertexAttribP2uiv", &opengl_lib),
            glVertexAttribP3ui: get_func(egl, "glVertexAttribP3ui", &opengl_lib),
            glVertexAttribP3uiv: get_func(egl, "glVertexAttribP3uiv", &opengl_lib),
            glVertexAttribP4ui: get_func(egl, "glVertexAttribP4ui", &opengl_lib),
            glVertexAttribP4uiv: get_func(egl, "glVertexAttribP4uiv", &opengl_lib),
            glVertexAttribPointer: get_func(egl, "glVertexAttribPointer", &opengl_lib),
            glVertexP2ui: get_func(egl, "glVertexP2ui", &opengl_lib),
            glVertexP2uiv: get_func(egl, "glVertexP2uiv", &opengl_lib),
            glVertexP3ui: get_func(egl, "glVertexP3ui", &opengl_lib),
            glVertexP3uiv: get_func(egl, "glVertexP3uiv", &opengl_lib),
            glVertexP4ui: get_func(egl, "glVertexP4ui", &opengl_lib),
            glVertexP4uiv: get_func(egl, "glVertexP4uiv", &opengl_lib),
            glVertexPointer: get_func(egl, "glVertexPointer", &opengl_lib),
            glViewport: get_func(egl, "glViewport", &opengl_lib),
            glWaitSync: get_func(egl, "glWaitSync", &opengl_lib),
            glWindowPos2d: get_func(egl, "glWindowPos2d", &opengl_lib),
            glWindowPos2dv: get_func(egl, "glWindowPos2dv", &opengl_lib),
            glWindowPos2f: get_func(egl, "glWindowPos2f", &opengl_lib),
            glWindowPos2fv: get_func(egl, "glWindowPos2fv", &opengl_lib),
            glWindowPos2i: get_func(egl, "glWindowPos2i", &opengl_lib),
            glWindowPos2iv: get_func(egl, "glWindowPos2iv", &opengl_lib),
            glWindowPos2s: get_func(egl, "glWindowPos2s", &opengl_lib),
            glWindowPos2sv: get_func(egl, "glWindowPos2sv", &opengl_lib),
            glWindowPos3d: get_func(egl, "glWindowPos3d", &opengl_lib),
            glWindowPos3dv: get_func(egl, "glWindowPos3dv", &opengl_lib),
            glWindowPos3f: get_func(egl, "glWindowPos3f", &opengl_lib),
            glWindowPos3fv: get_func(egl, "glWindowPos3fv", &opengl_lib),
            glWindowPos3i: get_func(egl, "glWindowPos3i", &opengl_lib),
            glWindowPos3iv: get_func(egl, "glWindowPos3iv", &opengl_lib),
            glWindowPos3s: get_func(egl, "glWindowPos3s", &opengl_lib),
            glWindowPos3sv: get_func(egl, "glWindowPos3sv", &opengl_lib),
            glStartTilingQCOM: get_func(egl, "glStartTilingQCOM", &opengl_lib),
            glEndTilingQCOM: get_func(egl, "glEndTilingQCOM", &opengl_lib),
        };

        Ok(Self {
            _opengl_lib_handle: opengl_lib,
            functions: Rc::new(context),
        })
    }
}
